﻿using UnityEngine;

public class HelpWordCtrl : CSIMediator
{
    private HelpWordPanel view;
    private ObjData helpData;
    
    public override void SetData(params object[] args)
    {
        helpData = (ObjData)args[0];
    }
    
    public override void Awake()
    {
        base.Awake();
        view = new HelpWordPanel(Go);
    }

    public override void Open()
    {
        base.Open(); 
        var table_GlobalHelp = TableDataMgr.GlobalHelpMgr.GetItemById(helpData.objId);
        if (table_GlobalHelp == null) { return; }

        view.Tip_txt.text = DBSystemMgr.GetSingleton().GetStringByID(table_GlobalHelp.Title);
        Utility.SetActive(view.Close_obj, table_GlobalHelp.TapClose);
        view.Info_txt.text = DBSystemMgr.GetSingleton().GetStringByID(table_GlobalHelp.ContentId, helpData.strArg);
        view.List_slv.ResetPosition();
    }

    public override void Close()
    {
        base.Close();
    }

    public override void Destroy()
    {
        view = null;
        helpData = null;
        base.Destroy();
    }

    public override void AddListener()
    {
        UIEventListener.Get(view.Close_obj).onClick = OnClick;
        UIEventListener.Get(view.OK_obj).onClick = OnClick;
    }

    public override int PanelId
    {
        get { return (int)PanelID.HelpWordPanel; }
    }
    
    private void OnClick(GameObject go)
    {
        Close(); //关闭界面
        if (helpData.callArg != null)
        {
            helpData.callArg[0]();
        }
    }
}